import subprocess
import tkinter as tk
import webbrowser
# 一些好用的解析接口
head_urls = ['https://jx.jsonplayer.com/player/?url=',
             'https://jx.playerjy.com/?url=',
             'https://jx.blbo.cc:4433/?url=']


flag = False
flag2 = False
flag3 = False
flag4 = False
def Tell_me() :
    global flag
    if flag==False:
        flag=False
        webbrowser.open("https://v.qq.com/")
    else:
        flag=False
def Tell_me2():
    global flag2
    if flag2==False:
        flag2=False
        webbrowser.open("https://www.iqiyi.com/")
    else:
        flag2=False
def Tell_me3():
    global flag3
    if flag3==False:
        flag3=False
        webbrowser.open("https://www.360kan.com/dianying/index.html?from=dongdong")
    else:
        flag3=False
def Tell_me4():
    global flag4
    if flag4==False:
        flag4=False
        webbrowser.open("https://www.mgtv.com/")
    else:
        flag4=False 

# 按键响应的处理函数
def handle_button_click(url, txt):
    full_url = url + txt.get()
    # print(full_url)
    subprocess.run(['start', full_url], shell=True, encoding='utf-8')


# 按键响应
def button_click(line, txt):
    handle_button_click(head_urls[line - 1], txt)


# 输入框的文本重置清空
def ent_cls(ent):
    ent.delete(0, "end")


# 置顶部分实现函数
def toggle_topmost(root):
    current_state = root.attributes("-topmost")  # 获取当前窗口的顶置状态
    root.attributes("-topmost", not current_state)  # 切换顶置状态

    # 清除该位置之前的布局内容
    previous_txt = root.grid_slaves(row=10, column=3)
    for widget in previous_txt:
        widget.grid_forget()

    # 未顶置按钮设置为绿色，顶置按钮设置为红色
    if root.attributes("-topmost") == 0:
        button = tk.Button(root, text="未顶置", command=lambda: toggle_topmost(root), fg='#19c37d')
        button.place(x=320, y=270)
    else:
        button = tk.Button(root, text="已顶置", command=lambda: toggle_topmost(root), fg='#ff1030')
        button.place(x=320, y=270)


def main():
    root = tk.Tk()
    # 窗口标题
    root.title(" VIP视频免费看工具 ")
    # 窗口大小
    root.geometry("380x310")
    # 不允许改变尺寸
    root.resizable(False, False)
    Mybutton=tk.Button(root, text='腾讯',font=('Arial', 10),command=Tell_me)
    Mybutton.place(x=40,y=60)

    Mybutton2=tk.Button(root, text='爱奇艺',font=('Arial', 10),command=Tell_me2)
    Mybutton2.place(x=100,y=60)

    Mybutton3=tk.Button(root, text='360影视',font=('Arial', 10),command=Tell_me3)
    Mybutton3.place(x=170,y=60)

    Mybutton4=tk.Button(root, text='芒果TV',font=('Arial',10),command=Tell_me4)
    Mybutton4.place(x=245,y=60)

    txt = tk.Label(root, text='请输入视频网址：', font=40, fg='#24abf2')
    txt.place(x=20, y=20)
    # 输入框
    key_word = tk.StringVar()
    ent = tk.Entry(root, textvariable=key_word)
    ent.place(x=170, y=20)

    # 输入框的文本重置按钮
    button_cls = tk.Button(root, text="重置", command=lambda: ent_cls(ent))
    button_cls.place(x=325, y=20)


    button2 = tk.Button(root, text="开始",font=('Arial',10), command=lambda: button_click(2, key_word))
    button2.place(x=163, y=140)


    root.mainloop()


if __name__ == "__main__":
    main()